home *** CD-ROM | disk | FTP | other *** search
- #ifdef xkernel
- #include "userupi.h"
- #include "userprocess.h"
- #include "debug.h"
- /* Eric Jul, Aug. 1989: all this is x stuff, so conditionally compile it */
-
- #include "Kernel/h/stdTypes.h"
- #include "Kernel/h/kEvents.h"
- #include "Kernel/h/emTypes.h"
- extern SSPtr currentSSP, readyQ, removeQ();
- /*
- * emPause:
- * Delay the calling process until something interesting happens (in UNIX
- * terms, interesting events were Signals).
- */
-
-
- int handlersWaiting = 0;
- int xkUtilsDebugging = 0;
- int nWaiting = 0;
- short int shouldPause, reallyPause, dontPause;
-
- emPause()
- {
- printf("in pause\n");
- abort();
- }
-
-
-
- becomeTheEmeraldScheduler()
- {
- xkhandlerstart();
- asm(" jmp kernel_exit");
- }
-
- startAnEmeraldScheduler()
- {
- if (xkUtilsDebugging) printf("%d: Creating em scheduler\n", xpid());
- xcreateprocess(becomeTheEmeraldScheduler, 5, 0);
- }
-
-
- holdsigs()
- {
- }
-
- releasesigs()
- {
- }
-
- Semaphore *waiting;
- static Semaphore *mutex;
-
- initXK()
- {
- waiting = xcreatesemaphore(0);
- mutex = xcreatesemaphore(1);
- }
-
- xkleaving(create)
- int create;
- {
- if (nWaiting > 0) {
- if (xkUtilsDebugging) printf("%d: Ving waiting = %d\n", xpid(), xsemcount(waiting));
- nWaiting --;
- xvsem(waiting);
- } else {
- if (xkUtilsDebugging) printf("%d: Releasing mutex = %d\n", xpid(), xsemcount(mutex));
- xvsem(mutex);
- if (xkUtilsDebugging) printf("%d: After release = %d\n", xpid(), xsemcount(mutex));
- if (create && handlersWaiting <= 0) {
- startAnEmeraldScheduler();
- }
- }
- }
-
- xkp(s)
- Semaphore *s;
- {
- if (xkUtilsDebugging) printf("%d: xkp %x = %d\n", xpid(), s, xsemcount(s));
- if (xsemcount(s) <= 0) {
- xkleaving(1);
- if (xkUtilsDebugging) printf("%d: Ping %x = %d\n", xpid(), s, xsemcount(s));
- xpsem(s);
- if (xkUtilsDebugging) printf("%d: Ping waiting = %d\n", xpid(), xsemcount(waiting));
- xpsem(waiting);
- } else {
- xpsem(s);
- }
- }
-
- xkv(s)
- Semaphore *s;
- {
- if (xkUtilsDebugging) printf("%d: xkv %x = %d, waiting = %d\n", xpid(), s,
- xsemcount(s), xsemcount(waiting));
- if (xsemcount(s) < 0) {
- nWaiting++;
- }
- xvsem(s);
- }
-
- doPause()
- {
- printf("In pause\n");
- abort();
- }
-
- xkhandlerstart()
- {
- if (xkUtilsDebugging) printf("%d: Handler starting\n", xpid());
- ++handlersWaiting;
- if (xkUtilsDebugging) printf("%d: Gaining mutex = %d\n", xpid(), xsemcount(mutex));
- xpsem(mutex);
- --handlersWaiting;
- if (xkUtilsDebugging) printf("%d: After gain = %d\n", xpid(), xsemcount(mutex));
- }
-
- xkhandlerend()
- {
- asm(" jmp kernel_exit");
- }
-
- char *emallocnil(x)
- register int x;
- {
- register long *p, *q;
- p = q = (long *) gc_malloc(x);
- x >>= 2;
- while (x--) {
- *q++ = 0x80000000;
- }
- return (char *) p;
- }
-
- doScheduling()
- {
- do {
- /* Check for other interested parties */
- if (xkUtilsDebugging) printf("%d: checking other handlers\n", xpid());
- if (handlersWaiting > 0) break;
-
- /* Check the task queue */
- if (xkUtilsDebugging) printf("%d: checking task q\n", xpid());
- if ((struct TaskQueue *)TaskQ.queue.F != &TaskQ) {
- if (xkUtilsDebugging) printf("%d: calling mainloop\n", xpid());
- MainLoop();
- continue;
- }
-
- /* Check for Emerald processes */
- if (NonNULL(currentSSP) ||
- NonNULL(currentSSP = removeQ(&readyQ))) {
- if (xkUtilsDebugging) printf("%d: running process 0x%X\n", xpid(), currentSSP);
- return;
- }
- break;
- } while (1);
- /* die */
- if (xkUtilsDebugging) printf("%d: doScheduling done, leaving\n", xpid());
- xkleaving(0);
- if (xkUtilsDebugging) printf("%d: doScheduling done, exiting\n", xpid());
- xexit();
- }
- #endif xkernel
-